<?php

// plugin
// name: Picture

class Picture {
	
	private		$id;
	private		$width;
	private		$height;
	private		$path;
	private		$alt;
	private		$title;
	
	// functions
	
	function Picture($i=NULL) {
		
		if (!$i) {
			throw new Exception("Couldn't create Picture.");
		}
		
		$this->id = $i;
		
		if($helpArray = $this->getfromdb($this->id)) {
			$this->path = $helpArray["path"];
			$this->width = $helpArray["width"];
			$this->height = $helpArray["height"];
			$this->alt = $helpArray["alt"];
			$this->title = $helpArray["title"];
		}
		
	}
	
	public function getfromdb($number) {
		$q = "SELECT image.path, image.width, image.height, image.alt, image.title FROM image WHERE image.id = " . $number;
		$r = mysql_query("set names 'utf8'");
		$r = mysql_query($q);
		if (mysql_num_rows($r)) {
			return (mysql_fetch_array($r));
		}
		else {
			return (array());
		}
	}
	
	function show() {
		$helpStr =  "<img src=\"media/pictures/" . $this->path ."\" alt=\"" . $this->alt ."\" title=\"" . $this->title ."\"";
		if ($this->width) $helpStr .= " width=\"" . $this->width . "\"";
		if ($this->height) $helpStr .= " height=\"" . $this->height ."\"";
		$helpStr .= " /><br />";
		
		return $helpStr;
	}
	
}

?>